@extends('layouts.main')

@section('title', '外部订单')

@section('content')
<h3>@yield('title')</h3>
<div class="btn-group" role="group">
  	<a href="{{ action('BusinessData\ExternalOrderDetailsController@create') }}" class="btn btn-primary">添加</a>
    <a href="{{ action('BusinessData\ExternalOrderDetailsController@import') }}" class="btn btn-warning">导入数据</a>
</div>

@if(session('success'))
<div class="alert alert-success" role="alert">{{ session('success') }}</div>
@endif

<div class="clearfix"></div>
<hr>

<form class="form-inline pull-right" method="get" action="{{ action('BusinessData\ExternalOrderDetailsController@index') }}">
    
    <div class="form-group ">
        <label for="year">年份</label>
        <div class='input-group' id='year'>
            <input type='text' name="year" class="form-control" value="{{ $request_params['year'] }}" />
        </div>
    </div>

    <div class="form-group ">
        <label for="payer_code">客户代码</label>
        <div class='input-group' id='payer_code'>
            <input type='text' name="payer_code" class="form-control" value="{{ $request_params['payer_code'] }}" />
        </div>
    </div>

    <button type="submit" name="search" value="search" class="btn btn-primary">查询</button>
    <button type="submit" name="delete" value="delete" class="btn btn-danger">根据条件删除数据</button>

</form>

<div class="clearfix"></div>
<hr>

<table class="table table-bordered table-striped table-hover">
    <tr>
		<th>id</th>
		<th>年份</th>
		<th>客户代码</th>
		<th>客户</th>
        <th>物料号</th>
        <th>品类</th>
        <th>数量</th>
        <th>金额</th>
		<th>操作</th>
    </tr>
  @forelse($models as $model)
	<tr>
		<td>{{ $model->id }}</td>
		<td>{{ $model->year }}</td>
		<td>{{ $model->payer_code }}</td>
		<td>{{ $model->payer ? $model->payer->name : '' }}</td>
		<td>{{ $model->material_code }}</td>
		<td>{{ $model->category_contract->name }}</td>
		<td>{{ $model->quantity }}</td>
        <td>{{ $model->amount }}</td>
		<td>
			<a href="{{ action('BusinessData\ExternalOrderDetailsController@edit', $model) }}" class="btn btn-warning btn-sm">编辑</a>
			<button name="delete" value="{{ $model->id }}" class="btn btn-danger btn-sm">删除</button>
		</td>
	</tr>
  @empty
  	<tr><td>暂无数据</td></tr>
  @endforelse
    <tr>
        <th>总计</th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th>{{ number_format($amount_total, 2) }}</th>
        <th></th>
    </tr>
</table>
{{ $models->appends([
    'year' => $request_params['year'],
    'payer_code' => $request_params['payer_code'],
    ])->links() }}
<script>
      $(document).ready(function(){
        //删除单个
        $("button[name=delete]").click(function(){
            var that = $(this);
            var id = that.attr("value");
            $.post("/business_data/external_order_details/" + id, {
                '_method': 'DELETE',
                '_token': '{{ csrf_token() }}',
            }, function(data){
                switch(data.status){
                    case 0:
                        that.parent().parent('tr').remove();
                        alert("删除信息成功！");
                        break;
                }
            });
        });


    });
</script>
@endsection